package com.fhz.day013;

import androidx.appcompat.app.AppCompatActivity;
import androidx.localbroadcastmanager.content.LocalBroadcastManager;

import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

public class MainActivity extends AppCompatActivity {
    LocalBroadcastManager instance;
    MyReceiver myReceiver;
    private Button send;
    private TextView show;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        instance = LocalBroadcastManager.getInstance(this);

         myReceiver = new MyReceiver();
        IntentFilter intentFilter = new IntentFilter();
        intentFilter.addAction("com.feng");
        instance.registerReceiver(myReceiver,intentFilter);


        send = (Button) findViewById(R.id.send);
        show = (TextView) findViewById(R.id.show);
        EventBus.getDefault().register(this);



    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        instance.unregisterReceiver(myReceiver);
        EventBus.getDefault().unregister(this);
    }



    @Subscribe(threadMode = ThreadMode.MAIN)
    public void getStr(String s){
        show.setText(s);
    }




    public void getStr1(String s){

    }
    public void send(View view) {
//        Intent intent = new Intent();
//        intent.setAction("com.feng");
//
//        instance.sendBroadcast(intent);
        Intent intent = new Intent(this,MainActivity2.class);
        startActivity(intent);
        EventBus.getDefault().postSticky("呵呵呵");


    }
}